/* 1768. 交替合并字符串 */
/**
 * @param {string} word1
 * @param {string} word2
 * @return {string}
 */
var mergeAlternately = function (word1, word2) {
	let ret = ''
	for (let i = 0; i < word1.length; i++) {
		ret += word1.charAt(i)
		if (word2.charAt(i)) {
			ret += word2.charAt(i)
		}
	}
	if (word2.length > word1.length) {
		ret += word2.slice(word1.length)
	}
	return ret
}
// 双指针
var mergeAlternately = function (word1, word2) {
	const m = word1.length,
		n = word2.length
	let i = 0,
		j = 0
	const ans = []
	while (i < m || j < n) {
		if (i < m) {
			ans.push(word1[i++])
		}
		if (j < n) {
			ans.push(word2[j++])
		}
	}
	return ans.join('')
}
